const requireDirectory = require('require-directory')
class InitManager {
    static init(app) {
       InitManager.app = app
       InitManager.loadRoutes()
       InitManager.loadGlobalErrors()
    }

    static loadRoutes() {
        const routeRootPath = `${process.cwd()}/route`
        requireDirectory(module, routeRootPath, {
            visit: function(routes) {
              InitManager.app.use(routes.routes())
            }
        })
    }

    static loadGlobalErrors() {
        const HttpException = require('./http-exception')
        global.errors = HttpException
    }
}

module.exports = InitManager